package com.dbflow5.sql.language.property;

import com.dbflow5.BaseUnitTest;
import com.dbflow5.models.SimpleTestModels;
import com.dbflow5.query.NameAlias;
import com.dbflow5.query.property.Property;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class CharPropertyTest extends BaseUnitTest {
    @Test
    public void testOperators() {
        Property<Character> prop = new Property<>(SimpleTestModels.SimpleModel.class, "Prop");
        assertEquals("Prop='5'", prop.is((char) '5').getQuery().trim());
        assertEquals("Prop='5'", prop.eq((char) '5').getQuery().trim());
        assertEquals("Prop!='5'", prop.notEq((char) '5').getQuery().trim());
        assertEquals("Prop!='5'", prop.isNot((char) '5').getQuery().trim());
        assertEquals("Prop>'5'", prop.greaterThan((char) '5').getQuery().trim());
        assertEquals("Prop>='5'", prop.greaterThanOrEq((char) '5').getQuery().trim());
        assertEquals("Prop<'5'", prop.lessThan((char) '5').getQuery().trim());
        assertEquals("Prop<='5'", prop.lessThanOrEq((char) '5').getQuery().trim());
        assertEquals("Prop BETWEEN '5' AND '6'", prop.between((char) '5').and((char) '6').getQuery().trim());
        assertEquals("Prop IN ('5','6','7','8')", prop.in((char) '5', (char) '6', (char) '7', (char) '8').getQuery().trim());
        assertEquals("Prop NOT IN ('5','6','7','8')", prop.notIn((char) '5', (char) '6', (char) '7', (char) '8').getQuery().trim());
        assertEquals("Prop=Prop || '5'", prop.concatenate((char) '5').getQuery().trim());
    }

    @Test
    public void testAlias() {
        Property<Character> prop = new Property<>(SimpleTestModels.SimpleModel.class, "Prop", "Alias");
        assertEquals("Prop AS Alias", prop.toString().trim());
        Property<Character> prop2 = new Property<>(SimpleTestModels.SimpleModel.class,
            NameAlias.builder("Prop").shouldAddIdentifierToName(false)
                .as("Alias")
                .shouldAddIdentifierToAliasName(false).build()
        );
        assertEquals("Prop AS Alias", prop2.toString().trim());
    }
}
